package com.chixing.ih.module.admin.controller;

import com.chixing.ih.json.ResponseData;
import com.chixing.ih.module.admin.pojo.dto.City;
import com.chixing.ih.module.admin.service.IAdminEchartsService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("AEC")
@Api(tags = "管理员Echarts相关Api")
public class AdminEchartsCon {

    @Autowired
    private IAdminEchartsService adminEchartsService;

    @ApiOperation(value = "查看订单数据接口", notes = "查看一年来每月完成订单数据")
    @ApiImplicitParams({})
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
    })
    @GetMapping("transactionData")
    public Map<String, Object> transactionData() {
        int year = Calendar.getInstance().get(Calendar.YEAR);
        List<Long> transactionList = new ArrayList<>();
        for (int i = 1; i <= 12; i++) {
            transactionList.add(adminEchartsService.transactionData(i, year));
        }
        return ResponseData.REP_GET_SUCCESS(transactionList);
    }

    @ApiOperation(value = "查看任务数据口", notes = "查看一年来每月发布任务数据")
    @ApiImplicitParams({})
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
    })
    @GetMapping("taskData")
    public Map<String, Object> taskData() {
        int year = Calendar.getInstance().get(Calendar.YEAR);
        List<Long> taskList = new ArrayList<>();
        for (int i = 1; i <= 12; i++) {
            taskList.add(adminEchartsService.taskData(i, year));
        }
        return ResponseData.REP_GET_SUCCESS(taskList);
    }

    @ApiOperation(value = "查看用户数据接口", notes = "查看六年来普通用户和Vip用户比例数据")
    @ApiImplicitParams({})
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
    })
    @GetMapping("userData")
    public Map<String, Object> userData() {
        int year = Calendar.getInstance().get(Calendar.YEAR) - 5;
        List<String> productList = new ArrayList<>();
        productList.add("product");
        productList.add("普通用户");
        productList.add("VIP用户");
        ArrayList<Object> DataList = new ArrayList<>();
        DataList.add(productList);
        for (int i = 0; i < 6; i++) {
            List<Integer> yearList = new ArrayList<>();
            yearList.add(year);
            yearList.add(adminEchartsService.userData(year));
            yearList.add(adminEchartsService.vipData(year));
            year++;
            DataList.add(yearList);
        }
        return ResponseData.REP_GET_SUCCESS(DataList);
    }

    @ApiOperation(value = "查看用户全国分布数据接口", notes = "查看用户全国分布数据")
    @ApiImplicitParams({})
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
    })
    @GetMapping("cityData")
    public Map<String, Object> cityData() {
        List<City> citys = adminEchartsService.cityData();
        return ResponseData.REP_GET_SUCCESS(citys);
    }


}
